package com.fenshi.manager.activity.order;

import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.graphics.Bitmap;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Toast;

import com.fenshi.manager.R;
import com.fenshi.presenter.DamageOrderPresenter;
import com.fenshi.presenter.imp.DamageOrderPresenterImp;
import com.fenshi.view.DamageOrderView;
import com.quickdv.activity.CameraActivity;
import com.quickdv.until.AlertHelper;

import java.util.HashMap;
import java.util.Map;

import butterknife.InjectView;
import butterknife.OnClick;

public class DamageOrderActivty extends CameraActivity implements View.OnClickListener, DamageOrderView {


    ProgressDialog load;
    AlertDialog dialog;
    Map<Integer,String> paths;
    DamageOrderPresenter presenter;
    @InjectView(R.id.image1)
    ImageView image1;
    @InjectView(R.id.linear1)
    LinearLayout linear1;
    @InjectView(R.id.image2)
    ImageView image2;
    @InjectView(R.id.linear2)
    LinearLayout linear2;
    @InjectView(R.id.image3)
    ImageView image3;
    @InjectView(R.id.linear3)
    LinearLayout linear3;
    @InjectView(R.id.image4)
    ImageView image4;
    @InjectView(R.id.linear4)
    LinearLayout linear4;
    @InjectView(R.id.image_description)
    EditText imageDescription;

    static int p = 0;

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_car_list, menu);
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            presenter.upDate();
//            finish();
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    @Override
    public int getLayoutID() {
        return R.layout.activity_damage_order_activty;
    }

    @Override
    public void initView() {
        AlertHelper helper = new AlertHelper(this);
        dialog = helper.BuildCameraDialog();
        load = helper.LoadingAlert();
    }

    @Override
    public void initActionbar() {

    }

    @Override
    public void initData() {
        presenter = new DamageOrderPresenterImp(this);
        paths = new HashMap<>();
    }


    @Override
    protected void onImageSelect(Bitmap bitMap, String path) {

        if (p ==1){
            image1.setImageBitmap(bitMap);
            image1.setScaleType(ImageView.ScaleType.CENTER_CROP);
            paths.put(1,path);

        }else if (p ==2){
            image2.setImageBitmap(bitMap);
            image2.setScaleType(ImageView.ScaleType.CENTER_CROP);
            paths.put(2,path);
        }else if (p ==3){
            image3.setImageBitmap(bitMap);
            image3.setScaleType(ImageView.ScaleType.CENTER_CROP);
            paths.put(3,path);
        }else if (p ==4){
            image4.setImageBitmap(bitMap);
            image4.setScaleType(ImageView.ScaleType.CENTER_CROP);
            paths.put(4,path);
        }
    }

    @OnClick({R.id.image1, R.id.image2,R.id.image3,R.id.image4})
    public void onClick(View view) {

        switch (view.getId()){
            case R.id.image4:
                p =4;
                break;
            case R.id.image3:
                p =3;
                break;
            case R.id.image2:
                p=2;
                break;
            case R.id.image1:
                p =1;
                break;
        }
        dialog.show();
    }

    @Override
    public void showInfo(String error) {
        Toast.makeText(this, error, Toast.LENGTH_LONG).show();
    }

    @Override
    public void showLoading() {
        if (load!=null && !load.isShowing()) load.show();
    }

    @Override
    public void dismissLoading() {
        if (load!=null && load.isShowing()) load.dismiss();
    }


    @Override
    public Map<Integer,String> getFilePath() {
        return paths;
    }

    @Override
    public String getDec() {
        return imageDescription.getText().toString();
    }



}
